﻿


Module Common

    ''' <summary>
    ''' returned when a crawler component tries to register for an already handled extension
    ''' </summary>
    ''' <remarks></remarks>
    Public Const E_EXTENSION_REGISTERED As Integer = &H80040001

    ''' <summary>
    ''' specifies that the component must register before performing any operations
    ''' </summary>
    ''' <remarks></remarks>
    Public Const E_COMPONENT_NOT_REGISTERED As Integer = &H80040002
    '''<summary>
    ''' returned when a component tries to use an inexistent schema
    '''</summary>
    Public Const E_NO_SUCH_SCHEMA As Integer = &H80040003
    '''<summary>
    ''' returned when a component tries to use an inexistent property
    ''' </summary>
    Public Const E_NO_SUCH_PROPERTY As Integer = &H80040004

    '''<summary>
    ''' specifies that the component has been disabled by the user
    ''' </summary>
    Public Const E_COMPONENT_DISABLED As Integer = &H80040005


    '''<summary> 
    ''' specifies that the component is already registered
    ''' </summary> 
    Public Const E_COMPONENT_ALREADY_REGISTERED As Integer = &H80040006

    '''<summary>
    ''' specifies that indexing is paused and any sent events will be ignored
    ''' </summary>
    Public Const S_INDEXING_PAUSED As Integer = &H80040007

    '''<summary>specifies that the event was rejected because of data size limits</summary>
    Public Const E_EVENT_TOO_LARGE As Integer = &H80040008

    ''' <summary>
    ''' specifies that Google Desktop is not running
    ''' </summary>
    Public Const E_SERVICE_NOT_RUNNING As Integer = &H80040009

    '''<summary>specifies that an event has invalid flags</summary>
    Public Const E_INVALID_EVENT_FLAGS As Integer = &H8004000A

    '''<summary>specifies that the component is prohibited by the user's group policy</summary>
    Public Const E_COMPONENT_PROHIBITED As Integer = &H8004000B

    '''<summary>specifies that the historical event sent could not be delivered immediately and a delay is recommended before sending again</summary>
    Public Const E_SEND_DELAYED As Integer = &H8004000C


    '''<summary>specifies that the provided property has been truncated due to size limits</summary>
    Public Const S_PROPERTY_TRUNCATED As Integer = &H8004000D

    '''<summary>specifies that the provided property is too large and cannot be accepted</summary>
    Public Const E_PROPERTY_TOO_LARGE As Integer = &H8004000E


    '''<summary>returned when a property is not set</summary>
    Public Const E_PROPERTY_NOT_SET As Integer = &H8004000F

    '''<summary>returned when the Google Desktop system is exiting.</summary>
    Public Const E_SERVICE_IS_EXITING As Integer = &H80040010

    '''<summary> returned when the application that made the call is exiting</summary>
    Public Const E_APPLICATION_IS_EXITING As Integer = &H80040011

    '''<summary> specifies that the event could not be delivered and a re-send is required</summary>
    Public Const E_RETRY_SEND As Integer = &H80040012

    '''<summary>
    ''' specifies that the event could not be delivered because required
    ''' resources were not available and the send operation timed out
    ''' </summary> 
    Public Const E_SEND_TIMEOUT As Integer = &H80040013

    '''<summary> specifies that the gadget registration was cancelled by the user</summary>
    Public Const E_REGISTRATION_CANCELLED_BY_USER As Integer = &H80040014

    '''<summary>specifies that the search has been locked by the user</summary>
    Public Const E_SEARCH_LOCKED As Integer = &H80040015




    Function GetComponentGUID(ByVal t As System.Type) As String
        Return "{" & t.GUID.ToString & "}"
    End Function



    Function LogException(ByVal ex As Exception) As Boolean
        My.Application.Log.WriteException(ex)

        Return False
    End Function



    Sub GDException(ByVal ex As COMException)
        Select Case ex.ErrorCode
            Case E_APPLICATION_IS_EXITING
                Throw New ApplicationIsExitingException

            Case E_COMPONENT_ALREADY_REGISTERED
                Throw New ComponentAlreadyRegisteredException
            Case Common.E_COMPONENT_DISABLED
                Throw New ComponentDisabledException
            Case Common.E_COMPONENT_NOT_REGISTERED
                Throw New ComponentNotRegisteredException
            Case Common.E_COMPONENT_PROHIBITED
                Throw New ComponentProhibitedExpction


            Case Common.E_EVENT_TOO_LARGE
                Throw New EventTooLargeException

            Case Common.E_EXTENSION_REGISTERED
                Throw New ExtensionRegisteredException

            Case Common.E_INVALID_EVENT_FLAGS
                Throw New InvalidEventFlagsException

            Case Common.E_NO_SUCH_PROPERTY
                Throw New NoSuchPropertyException
            Case Common.E_NO_SUCH_SCHEMA
                Throw New NoSuchSchemaException

            Case Common.E_PROPERTY_NOT_SET
                Throw New PropertyNotSetException

            Case Common.E_PROPERTY_TOO_LARGE
                Throw New PropertyTooLargeException

            Case Common.E_REGISTRATION_CANCELLED_BY_USER
                Throw New RegistrationCancelledByUserException

            Case Common.E_RETRY_SEND
                Throw New RetrySendExcpetion

            Case Common.E_SEARCH_LOCKED
                Throw New SearchLockedException

            Case Common.E_SEND_DELAYED
                Throw New SendDelayedException
            Case Common.E_SEND_TIMEOUT
                Throw New SendTimeoutException

            Case Common.E_SERVICE_IS_EXITING
                Throw New ServiceIsExitingException
            Case Common.E_SERVICE_NOT_RUNNING
                Throw New ServiceNotRunningException

            Case Common.S_INDEXING_PAUSED
                Throw New IndexingPausedException

            Case Common.S_PROPERTY_TRUNCATED
                Throw New PropertyTruncatedException


        End Select
    End Sub




End Module
